package com.jt.auth.config;

import com.jt.auth.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.DefaultAuthenticationEventPublisher;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Slf4j
@Component
public class SSOAuthListener extends DefaultAuthenticationEventPublisher {
    @Override
    public void publishAuthenticationSuccess(Authentication authentication) {
        super.publishAuthenticationSuccess(authentication);
        UserDetails principal = (UserDetails) authentication.getPrincipal();
        log.info("{} login success {}",principal.getUsername(), LocalDate.now());
//        remoteLogService.saveLog();
    }

    @Override
    public void publishAuthenticationFailure(AuthenticationException exception, Authentication authentication) {
        super.publishAuthenticationFailure(exception, authentication);
        log.info("login falture {} {}", LocalDateTime.now(),exception.getMessage());
    }
}
